<?php

/**
 * This is the model class for table "{{comision_mixta_cap}}".
 *
 * The followings are the available columns in table '{{comision_mixta_cap}}':
 * @property integer $ID_COMISION_MIXTA
 * @property integer $ID_EMPRESA
 * @property integer $COMISION_MIXTA_PADRE
 * @property integer $NUMERO_INTEGRANTES
 * @property string $FECHA_CONSTITUCION
 * @property string $FECHA_ELABORACION
 * @property integer $ACTIVO
 *
 * The followings are the available model relations:
 * @property Establecimiento[] $tblEstablecimientos
 * @property Empresa $iDEMPRESA
 * @property ComisionMixta $cOMISIONMIXTAPADRE
 * @property ComisionMixta[] $comisionMixtaCaps
 */
class ComisionMixta extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return ComisionMixta the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{comision_mixta_cap}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ID_EMPRESA, COMISION_MIXTA_PADRE, NUMERO_INTEGRANTES, ACTIVO', 'numerical', 'integerOnly'=>true),
			array('FECHA_CONSTITUCION, FECHA_ELABORACION', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_COMISION_MIXTA, ID_EMPRESA, COMISION_MIXTA_PADRE, NUMERO_INTEGRANTES, FECHA_CONSTITUCION, FECHA_ELABORACION, ACTIVO', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tblEstablecimientos' => array(self::MANY_MANY, 'Establecimiento', '{{comision_establecimiento}}(ID_COMISION_MIXTA, ID_ESTABLECIMIENTO)'),
			'iDEMPRESA' => array(self::BELONGS_TO, 'Empresa', 'ID_EMPRESA'),
			'cOMISIONMIXTAPADRE' => array(self::BELONGS_TO, 'ComisionMixta', 'COMISION_MIXTA_PADRE'),
			'comisionMixtaCaps' => array(self::HAS_MANY, 'ComisionMixta', 'COMISION_MIXTA_PADRE'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_COMISION_MIXTA' => 'Id Comision Mixta',
			'ID_EMPRESA' => 'Id Empresa',
			'COMISION_MIXTA_PADRE' => 'Comision Mixta Padre',
			'NUMERO_INTEGRANTES' => 'Numero Integrantes',
			'FECHA_CONSTITUCION' => 'Fecha Constitucion',
			'FECHA_ELABORACION' => 'Fecha Elaboracion',
			'ACTIVO' => 'Activo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_COMISION_MIXTA',$this->ID_COMISION_MIXTA);
		$criteria->compare('ID_EMPRESA',$this->ID_EMPRESA);
		$criteria->compare('COMISION_MIXTA_PADRE',$this->COMISION_MIXTA_PADRE);
		$criteria->compare('NUMERO_INTEGRANTES',$this->NUMERO_INTEGRANTES);
		$criteria->compare('FECHA_CONSTITUCION',$this->FECHA_CONSTITUCION,true);
		$criteria->compare('FECHA_ELABORACION',$this->FECHA_ELABORACION,true);
		$criteria->compare('ACTIVO',$this->ACTIVO);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}